package com.gdcn.zb.sys.service.impl;

import java.util.List;

import com.gdcn.zb.base.BaseService;
import com.gdcn.zb.base.exception.DaoException;
import com.gdcn.zb.base.exception.ServiceException;
import com.gdcn.zb.sys.dao.IUserDao;
import com.gdcn.zb.sys.service.IUserService;
import com.gdcn.zb.sys.valueobject.User;


public class UserServiceImpl extends BaseService implements IUserService {
	private IUserDao userDao ;
	
	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
	public void createUser(User user) throws ServiceException {
		try{
			userDao.createUser(user);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
	}

	public void deleteUser(String id) throws ServiceException {
		try{
			userDao.deleteUser(id);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		
	}

	public User findUserById(String id) throws ServiceException {
		User user = null;
		try{
				user = userDao.findUserById(id);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		return user;
	}

	public void updateUser(User user) {
		try{
			userDao.updateUser(user);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}		
	}
	public List listUserOfAll() throws ServiceException {
		List list = null;
		try{
			String hql = "from User";
			list = userDao.listUser(hql);
		}catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		return list;
	}
	
	public void deleteUser(String[] id) throws ServiceException {
		if(id != null){
			for(int i=0;i<id.length;i++){
				deleteUser(id[i]);
			}
		}
	}
}
